using AvaDemo.Services;
using AvaDemo.ViewModels;
using AvaDemo.Views;
using AvaDemo.Views.Dialogs;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection;
using SukiUI.Controls;
using System;

namespace AvaDemo
{
    public partial class App : Application
    {

        private IServiceProvider _provider;
        public override void Initialize()
        {
            AvaloniaXamlLoader.Load(this);
            var services = new ServiceCollection();
            services.InitialXTServices();
            services.AddKeyedSingleton<ViewBase, DialogOneViewModel>("DialogOne");
            _provider = services.BuildServiceProvider();
        }

     
    
        public override void OnFrameworkInitializationCompleted()
        {
            

            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            {
                desktop.MainWindow = new MainWindow
                {
                    DataContext = new MainViewModel(),
                };
            }
            ApplicationLifetime?.InitialCompleted(_provider);
            base.OnFrameworkInitializationCompleted();
        }

        private void NativeMenuItem_Click(object? sender, EventArgs e)
        {
            if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
            {
                lifetime?.Shutdown();

            }
        }

        private void NativeMenuItem_Show(object? sender, EventArgs e)
        {
            if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
            {
                var window = lifetime?.MainWindow;
                window.WindowState = WindowState.Normal;
                window.Show();


            }
        }
    }
}